<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	<h4 class="modal-title"><font color="red">用户信息</font>&nbsp;</h4>
</div>
<div class="modal-body">
	<form class="form-horizontal" role="form" id="userForm">
		<input type="hidden" name="formToken" id="formToken">
		<input type="hidden" name="userId" class="clean" id="userId" data-name="userId">
		<input type="hidden" name="userPass" class="clean" id="md5Pass" value=""/>
		<input type="hidden" name="delStatus" class="clean" id="delStatus" data-name="delStatus" value="2"/>
		<input type="hidden" name="auditStatus" value="91"/>
		<input type="hidden" name="customerType" value="org"/>
		<input type="hidden" name="regSource" value="plate"/>
		<input type="hidden" name="randCodeMark" value="F">
		<div class="box-body" id="userFormData">
			<div class="form-group">
			   <label for="inputOrgCname" class="col-sm-2 control-label" >账号</label>
			   <div class="col-sm-6">
			       <input type="text" class="form-control clean" data-name="userEname" name="userEname" required placeholder="必填项">
			   </div>
			   <div class="col-sm-4">
			       <div data-name="userEname"  data-type-tag="qrcode"></div>
			   </div>
			</div>
			<div class="form-group">
			    <label class="col-sm-2 control-label">姓名</label>
			    <div class="col-sm-8">
			         <input type="text" class="form-control clean"  name="userCname" data-name="userCname" required placeholder="必填项">
			    </div>
			</div>
			<div id="if_update_pass_div" class="form-group" style="display: none">
			    <label class="col-sm-2 control-label">是否修改密码</label>
			    <div class="col-sm-8">
			       <input type="radio" name="if_update_pass" value="1" onclick="setUserPass('1')"/>是
                   <input type="radio" name="if_update_pass" value="0" checked="checked" onclick="setUserPass('0')"/>否
			    </div>
			</div>
			<div id="edit_user_pass">
			<div class="form-group">
			     <label class="col-sm-2 control-label">密码</label>
			     <div class="col-sm-8">
			         <input type="password" class="form-control clean" id="password">
			     </div>
			</div>
			<div class="form-group">
			     <label class="col-sm-2 control-label">确认密码</label>
			     <div class="col-sm-8">
			           <input type="password" class="form-control clean" id="password2"  type="password">
			     </div>
			 </div>
			 </div>
			 <div class="form-group">
			     <label class="col-sm-2 control-label">邮箱</label>
			     <div class="col-sm-8">
			          <input type="text" class="form-control clean" name="email" data-name="email" placeholder="">
			     </div>
			  </div>
			  <div class="form-group">
			       <label class="col-sm-2 control-label">用户类型</label>
			       <div class="col-sm-8">
			            <select id="userType" name="userType" class="form-control clean" >
			                  <option value=''>--请选择--</option>
			            </select>
			       </div>
			  </div>
			  <div class="form-group">
			       <label class="col-sm-2 control-label">所属机构</label>
			       <div class="col-sm-8">
			            <select id="orgId" name="orgId" class="form-control clean" onchange="initDept('deptId',this.value);"></select>
			       </div>
			 </div>
			 <div class="form-group">
			      <label class="col-sm-2 control-label">所属部门</label>
			      <div class="col-sm-8">
			           <select id="deptId" name="deptId"  class="form-control clean">
			               <option value=''>--请选择--</option>
			           </select>
			      </div>
			</div>
			<!-- div class="form-group">
			     <label class="col-sm-2 control-label">上级领导</label>
			     <div class="col-sm-8">
			         <input type="text" class="form-control" name="fax"  placeholder="非必填项">
			     </div>
			 </div-->
			 <div class="form-group" id="if-userSex">
			      <label class="col-sm-2 control-label">用户性别</label>
			      <div class="col-sm-8" id="userSexDiv"></div>
			 </div>
			 <div class="form-group">
			      <label class="col-sm-2 control-label">手机</label>
			      <div class="col-sm-8">
			           <input type="text" class="form-control clean" name="mobile" data-name="mobile" placeholder="非必填项" maxlength="11">
			      </div>
			 </div>
			 <div class="form-group">
			       <label class="col-sm-2 control-label">联系电话</label>
			       <div class="col-sm-8">
			            <input type="text" class="form-control clean" name="phone" data-name="phone" placeholder="非必填项">
			       </div>
			 </div>
			 <div class="form-group">
			      <label class="col-sm-2 control-label">状态</label>
			      <div class="col-sm-8">
			           <input type="radio"  value="1" name="userStatus" checked="checked"/> 启用 
                       <input type="radio" value="0" name="userStatus"/>停用
			      </div>
			  </div>
			  <div class="form-group" id="if-sysFlag">
			      <label class="col-sm-2 control-label">用户类别</label>
			      <div class="col-sm-8">
					  <span class="form-control-static">机构管理员（默认）</span>
					  <!--<input type="radio" name="delStatus" id="delStatus_2" value="2"  checked="checked"/>机构管理员
					  <input type="radio" name="delStatus" id="delStatus_1" value="1" />1平台用户
					  <input type="radio" name="delStatus"  id="delStatus_3" value="3" checked="checked" />3机构系统管理员
					  <input type="radio" name="delStatus"  id="delStatus_0" value="0" checked="checked" />0机构用户-->
			      </div>
			  </div>
			  </div>
			  <div class="box-footer">
			        <button type="button" class="btn btn-success pull-left" onclick="cannel('my_modal');"> 取消 </button>
			        <button type="button" id="btn_add" class="btn btn-primary pull-right hidden" onclick="add('userForm');"> 新增提交 </button>
			        <button type="button" id="btn_edit" class="btn btn-primary pull-right hidden" onclick="edit('userForm');"> 修改提交 </button>
			  </div>
	</form>
</div>
<script>
function toEdit(){
	if(strUtil.isNull(id)){
		layer.alert('请先选中一条数据！', {skin: 'layui-layer-molv',closeBtn: 0 });
		return;
	}else{
		$("#btn_edit").removeClass("hidden");
		$("#btn_add").addClass("hidden");
		mytools.cleanData("#userForm");
	   $("#if_update_pass_div").show();
	   $("#edit_user_pass").hide();
	   $("#if-sysFlag").hide();
	   $("#userFormData").find("input[name='userEname']").prop("readonly",true);
	   $("#userFormData").find("input[name='if_update_pass'][value='0']").prop("checked",true);
        $.ajax({
		
			type:'get', url:view_url,
		    data:{'userId':id,'doCode':'U0007'},
		    dataType:'json',
		    success: function(myData){
		    //console.log(myData);
		    
		    	 initDept("deptId",myData.orgId);
		    
				 getObjInfo(myData);
				 $("#userId").val(myData.userId);
				 var myobj=document.getElementById("userType");
				 if(myobj==null)return;
				 for ( var i = 0; i < myobj.options.length; i++) {
					if (myobj.options[i].value == myData.userType) {
						myobj.selectedIndex = i;
					}
				 }
				 var myobj=document.getElementsByName("userStatus");
				if(myobj==null)return;
				for ( var i = 0; i < myobj.length; i++) {
					if (myobj[i].value == myData.userStatus) {
						myobj[i].checked = "true";
					}
				 }
				 var myobj2=document.getElementsByName("delStatus");
				if(myobj2==null)return;
				for ( var i = 0; i < myobj2.length; i++) {
					if (myobj2[i].value == myData.delStatus) {
						myobj2[i].checked = "true";
					}
				 }
				 
				DictUtil.checkSelectDict("#userType", myData.userType);
				DictUtil.checkSelectDict("#orgId", myData.orgId);
				DictUtil.checkSelectDict("#deptId", myData.deptId);
				 
		  	}
		});	
	}
}

function del(){
	if(strUtil.isNull(id)){
		layer.alert('请先选中一条数据！', {skin: 'layui-layer-molv',closeBtn: 0});
		return;
	}else{
		if("${loginUser.userId}"==id){
			layer.alert('自己不能删除自己！', {skin: 'layui-layer-molv',closeBtn: 0});
			return;
		}
		var index_submit = layer.confirm("您确认删除 用户["+userCname+"]吗？", {btn: ['确认','取消'],closeBtn: 0,offset: '220px'}
		, function(){
			layer.close(index_submit);
			var formToken = $("#formToken").val();
			$.ajax({ type:'post', url:del_url,
			    data:{'userId':id,'formToken':formToken}, dataType:'json',
			    success: function(myData){
			    	if(myData.flag=='T'){
			    		layer.alert('删除成功！', { skin: 'layui-layer-molv',closeBtn: 0 });
			    		refresh();
			    	}
			  	}
			});	
		})
	}
}

function add(formId){
		var pass = $("#password").val();
	    var pass2 = $("#password2").val();
	    if($.trim(pass) != $.trim(pass2)){
	    	$.messager.alert('错误提示', '两次输入密码不一致!', 'error');
	    	return;
	    }else{
	    	if(!strUtil.isNull(pass)){
		    	$("#md5Pass").val(pass.md5());
	    	}
	    }
	_submit(formId);
}
function edit(formId){
  // if(!$("#" + formId)[0].checkValidity()){
//		layer.alert('请先完善必输项和必选项！', { skin: 'layui-layer-molv',closeBtn: 0 });
    	//var item = $('input[name="if_update_pass"][checked]').val(); 
    	var item=$('input:radio[name="if_update_pass"]:checked').val();
		if("1"==item){
		    var pass = $("#password").val();
	    	var pass2 = $("#password2").val();
	    	if(strUtil.isNull(pass)){
	    		layer.alert("密码不能为空！");
	    		return;
	    	}
	    	if(pass!= pass2){
	    		layer.alert("两次输入密码不一致!");
	    		return;
	    	}else{
	    		$("#md5Pass").val(pass.md5());
	    	}
		}else{
			$("#password").attr("disabled","true");
			$("#password2").attr("disabled","true");
		}
		//return ;
	//}
	_submit(formId);
}
function _submit(formId){
	var index_submit = layer.confirm('您确定要保存信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		layer.close(index_submit);
			$.ajax({type:'post', url:add_url,dataType:'json',
			    data:$("#"+formId).serialize(),
			    success: function(myData){
			    	//console.log(myData);
			    		layer.alert(myData.msg, {skin: 'layui-layer-molv',closeBtn: 0});
			    	if(myData.flag=='T'){
			    		$('#my_modal').modal('hide');
			    		refresh();
			    	}
			  	}
			});	
	});
   
}
function setUserPass(ifPass){
    if("1"==ifPass){
        $("#edit_user_pass").show();
    }else{
    	$("#password").val("");
		$("#password2").val("");
        $("#edit_user_pass").hide();
    }
}

</script>
